package com.neo.sk.util

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource
import com.zaxxer.hikari.HikariDataSource
import org.slf4j.LoggerFactory
import com.neo.sk.common.AppSettings._
import scala.slick.driver.MySQLDriver.simple._

/**
 * User: Huangshanqi
 * Date: 2015/6/2
 * Time: 15:22
 */
object DBUtil {
  val log = LoggerFactory.getLogger(this.getClass)
  
  private val dataSource = createDataSource()

  private def createDataSource() = {
    //hikariDS.setDataSource(DB.getDataSource())

    val mysqlDS = new MysqlDataSource()
    mysqlDS.setURL(slickUrl)
    mysqlDS.setUser(slickUser)
    mysqlDS.setPassword(slickPassword)

    val hikariDS = new HikariDataSource()
    hikariDS.setDataSource(mysqlDS)
    hikariDS.setMaximumPoolSize(slickMaximumPoolSize)
    hikariDS.setConnectionTimeout(slickConnectTimeout)
    hikariDS.setIdleTimeout(slickIdleTimeout)
    hikariDS.setMaxLifetime(slickMaxLifetime)
    hikariDS.setAutoCommit(true)

    hikariDS
  }


  val db = Database.forDataSource(dataSource)


}